<?php

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 5, $gametype);
$chk->checkShow3dPage();
unset($chk);
$tbl = $g_gametype_3d[$gametype]['en'];
require_once( "class_5h/RateConfig_5h.php" );
require_once( "class_5h/BetTotal_5h.php" );
$order = getvar("order");
$split = getvar("split");
$disk = getvar("disk");
$ratemod = getvar("ratemod");
$playtype = getvar("playtype");
$lotto_id = intval(getvar("lotto_id"));
$bid = getvar("bid");
$bidArr = $bid !== "" ? explode(",", $bid) : array();
$bnowAcl = getvar("bnowAcl");
$showSubid = getvar("subid");
$xyid = intval(getvar("xyid"));
if ($lotto_id < 1)
{
    header("Cache-Control: no-cache, must-revalidate");
    header("Content-Type: text/plain");
    echo "{\"errormsg\":\"no data\"}";
    exit();
}
if (20 < $gametype)
{
    $_8hFlag = true;
} else
{
    $_8hFlag = false;
}
$RateConfig_5h = new RateConfig_5h($gametype);
$BetTotal_5h = new BetTotal_5h($lotto_id, $gametype);
$split = isset($RateConfig_5h->splitArr[$split]) ? $split : "0";
$disk = isset($RateConfig_5h->diskArr[$disk]) ? $disk : 0;
$order = isset($RateConfig_5h->orderArr[$order]) ? $order : 0;
$ratemod = isset($RateConfig_5h->ratemodArr[$ratemod]) ? $ratemod : 2;
$playtype = isset($RateConfig_5h->playtypeArr02[$playtype]) ? $playtype : "r1";
$showSubid = isset($RateConfig_5h->subArr[$showSubid]) ? $showSubid : "0";
$xyid = isset($RateConfig_5h->xyidArr[$xyid]) ? $xyid : 0 - 1;
$time = systime() - 30;
if ($disk == 0)
{
    $diskStr = "";
} else
{
    $diskStr = $RateConfig_5h->diskArr[$disk];
}
$sObj = NULL;
$rateArr = NULL;
$tempStr = "";
$bidArrNum = count($bidArr);
if ($bid !== "" && $bidArrNum == 1 && in_array($bid, $RateConfig_5h->playGroupArr02[$playtype]))
{
    $playArr = array(0 => $bid);
} else if (1 < $bidArrNum && count(array_intersect($RateConfig_5h->playGroupArr02[$playtype], $bidArr) == $bidArrNum))
{
    $playArr = $bidArr;
} else
{
    $playArr = $RateConfig_5h->playGroupArr02[$playtype];
}
$acl5bnow = false;
if ($curruser['acl'] == "5" && $bnowAcl == "5")
{
    $acl5bnow = true;
}
$rArr = array();
$rWin = array();
$rAmn = array();
$rtotalArr = array();
$pgTotalAmountArr = array();
$companyFlag = true;
if ($curruser['acl'] == 255)
{
    $showid = "0";
    $companyFlag = false;
} else
{
    $showid = $curruser['id'];
    $companyFlag = true;
}
if ($ratemod == 0)
{
    include( "class_5h/SRate_5h.php" );
    $SRate_5h = new SRate_5h($gametype);
    $user_id = $SRate_5h->getAcl5ID($curruser['id'], $curruser['acl']);
}
include_once( "class_5h/Bet_5h.php" );
$openDate = date("Y-m-d");
$rs = getdb("SELECT open FROM lotto_{$tbl} WHERE id = {$lotto_id} LIMIT 1");
if (!$rs->eof)
{
    $openDate = $rs->f[0];
}
$rs->close();
$postTime = $conf->get("paper_post_bet");
$today = date("Hi") <= $postTime ? date("Y-m-d", strtotime("-1 day")) : date("Y-m-d");
if ($openDate == $today)
{
    $Bet_5h = new Bet_5h($gametype);
} else
{
    $Bet_5h = new Bet_5h($gametype, "x");
}
$showids = $Bet_5h->getMyMemberIdByAcl($curruser['id'], $curruser['acl']);
$getDiffTotalArr = array();
$modDiffArr = array();
$rateArr = array();
$orderNumArr = array();
if ($_8hFlag)
{
    $orderDiffArr = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 18);
} else
{
    $orderDiffArr = array(1, 2, 3, 4, 5, 6, 7, 8);
}
$subEndNum = $_8hFlag ? 9 : 6;
foreach ($playArr as $val)
{
    if (in_array($val, $g_bet4subArr[$gametype]))
    {
        $subStart = 1;
        $subEnd = $subEndNum;
        if ($gametype == 24)
        {
            switch ($val)
            {
                case 3:
                case 4:
                case 5:
                    $orderDiffArr = array(0);
                    $subStart = 0;
                    $subEnd = 1;
                    break;
                case 6:
                    $subidArr = array(1, 2, 3, 4, 5);
                    $subEnd = 6;
                    break;
                default:
                    $orderDiffArr = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
                    $subEnd = 11;
                    break;
            }
        }
    } else
    {
        $subStart = 0;
        $subEnd = 1;
    }
    $subid = $subStart;
    while ($subid < $subEnd)
    {
        $val_subid = $val . "_" . $subid;
        $tempDataTotal = $BetTotal_5h->getDataListTotal($lotto_id, $val_subid, $showid, $split, $diskStr, $xyid);
        $numbersArr = $RateConfig_5h->getBetTypeNumber($val);
        $numberstr = implode("\",\"", $numbersArr);
        $numberstr = "\"" . $numberstr . "\"";
        if ($ratemod == 0)
        {
            if ($disk == 0)
            {
                $mydisk = 1;
            } else
            {
                $mydisk = $disk;
            }
            $tempRatesStr = $SRate_5h->getRates($lotto_id, $xyid, $mydisk, $val, $subid);
            if ($tempRatesStr == false)
            {
                $tempRateBaseArr = array();
                foreach ($RateConfig_5h->rateFieldArr as $numbersArrVal)
                {
                    $tempRateBaseArr[$numbersArrVal] = 0;
                }
            } else
            {
                $tempRateBaseArr = $tempRatesStr;
            }
            if ($acl5bnow)
            {
                $rateArr[$val_subid] = $tempRateBaseArr;
            } else if ($companyFlag && is_array($tempRatesStr2 = $SRate_5h->getRatesS($lotto_id, $val, $user_id, $subid)))
            {
                $tempRateArr = array();
                $tempRateBaseArr2 = $tempRatesStr2;
                foreach ($RateConfig_5h->rateFieldArr as $val2)
                {
                    $tempRateArr[$val2] = $tempRateBaseArr[$val2] - $tempRateBaseArr2[$val2];
                }
                $rateArr[$val_subid] = $tempRateArr;
            } else
            {
                $rateArr[$val_subid] = $tempRateBaseArr;
            }
        }
        if ($order == "1")
        {
            $orderby = "amount";
        } else
        {
            $orderby = "amount_rate";
        }
        if ($tempDataTotal != false)
        {
            $dataTotal = intval($tempDataTotal['totalnum']);
            $dataAmount = round($tempDataTotal['amount']);
            $databack2 = intval($tempDataTotal['back2']);
            if (isset($modDiffArr[$val]))
            {
                $databack1 = round($tempDataTotal['back1'] / $modDiffArr[$val]);
            } else
            {
                $databack1 = round($tempDataTotal['back1']);
            }
            if ($cutData = $RateConfig_5h->chkG3G6Idx($val))
            {
                $dataTotal = intval($dataTotal / $cutData);
                $dataAmount = round($dataAmount / $cutData);
                $databack2 = intval($databack2 / $cutData);
                $databack1 = intval($databack1 / $cutData);
            } else
            {
                if ($val == 46)
                {
                    $cutData = 3;
                    $dataTotal = intval($dataTotal / $cutData);
                    $dataAmount = round($dataAmount / $cutData);
                    $databack2 = intval($databack2 / $cutData);
                    $databack1 = intval($databack1 / $cutData);
                }
            }
        } else
        {
            $dataTotal = "0";
            $dataAmount = "0";
            $databack2 = "0";
            $databack1 = "0";
        }
        $rtotalArr[] = "\"r" . $val_subid . "total\":{\"totalnum\":\"" . $dataTotal . "\",\"amount\":\"" . $dataAmount . "\"}";
        if (isset($modDiffArr[$val]))
        {
            $winlostTemp = ( $dataAmount - $databack1 ) / $modDiffArr[$val];
        } else
        {
            $winlostTemp = $dataAmount - $databack1;
        }
        if ($companyFlag)
        {
            $winlostTemp = $winlostTemp + $databack2;
        }
        $winlostTemp = round($winlostTemp);
        $rArr[$val_subid] = $RateConfig_5h->my_array_fill_keys($numbersArr, array(0 - 1, 0, 0, 0, $winlostTemp, ""));
        $rWin[$val_subid] = $RateConfig_5h->my_array_fill_keys($numbersArr, $winlostTemp);
        $rAmn[$val_subid] = $RateConfig_5h->my_array_fill_keys($numbersArr, 0);
        $rs = $BetTotal_5h->getDataListByNumSs($lotto_id, $val, $numberstr, $showid, $diskStr, $split, $ratemod, $orderby, $subid, $xyid);
        while (!$rs->eof)
        {
            if (isset($modDiffArr[$val]))
            {
                $winlost = ( $dataAmount - $databack1 ) / $modDiffArr[$val] - $rs->f['amount_rate'];
            } else
            {
                $winlost = $dataAmount - $rs->f['amount_rate'] - $databack1;
            }
            if ($companyFlag)
            {
                $winlost = $winlost + $databack2;
            }
            $winlost = round($winlost);
            $totalnum = intval($rs->f['totalnum']);
            $amount = $rs->f['amount'];
            $amount = round($amount);
            $rate = floatval($rs->f['rate']);
            $numbers = (string) $rs->f['numbers'];
            $rate = floatval($rs->f['rate']);
            if ($time < $rs->f['updatetime'])
            {
                $bgclass = "namount";
            } else
            {
                $bgclass = "";
            }
            $rArr[$val_subid][$numbers] = array($numbers, $totalnum, $amount, $rate, $winlost, $bgclass);
            $rWin[$val_subid][$numbers] = $winlost;
            $rAmn[$val_subid][$numbers] = $amount;
            $rs->movenext();
        }
        if ($dataTotal < 1)
        {
            $orderTemp = 2;
        } else if (in_array($val, $orderDiffArr))
        {
            $orderTemp = 2;
        } else
        {
            $orderTemp = $order;
        }
        switch ($orderTemp)
        {
            case 0 :
                $tempArr = $rWin[$val_subid];
                asort($tempArr);
                reset($tempArr);
                break;
            case 1 :
                $tempArr = $rAmn[$val_subid];
                asort($tempArr);
                reset($tempArr);
                break;
            case 2 :
                $tempArr = $RateConfig_5h->my_array_fill_keys($numbersArr, 0);
                break;
        }
        $orderNumArr[$val_subid] = $tempArr;
        ++$subid;
    }
}
$listnumFlag = 0;
if ($ratemod == 0)
{
    $ratemodFlag = 1;
} else
{
    $ratemodFlag = 0;
}
$rStrArr = array();
foreach ($orderNumArr as $oKey => $oVal)
{
    $rStrTempArr = array();
    $oKeyArr = explode("_", $oKey);
    foreach ($oVal as $oKey2 => $oVal2)
    {
        $sData = $rArr[$oKey][$oKey2];
        $numTemp = $sData[0] < 0 ? $oKey2 : $sData[0];
        if ($gametype == 24 && $playtype == "r1")
        {
            $numTemp = (int) $numTemp;
        }
        if ($ratemodFlag)
        {
            $rateTemp = $RateConfig_5h->getRateFromRateArr($oKeyArr[0], $numTemp, $rateArr[$oKey]);
        } else
        {
            $rateTemp = $sData[3];
        }
        $rStrTempArr[] = "{\"numbers\":\"" . $numTemp . "\",\"totalnum\":\"" . $sData[1] . "\",\"amount\":\"" . $sData[2] . "\",\"rate\":\"" . $rateTemp . "\",\"winlost\":\"" . $sData[4] . "\",\"bgclass\":\"" . $sData[5] . "\"}";
        if ($listnumFlag && --$listnum < 1)
        {
            break;
        }
    }
    $rStrArr[] = "\"r" . $oKey . "\":[" . implode(",", $rStrTempArr) . "]";
}
if (!$showid && intval(getvar("onlinesum")))
{
    $conf = new Config();
    $member_max_limit = intval($conf->get("member_max_limit"));
    $onlinesum = 0;
    if ($playtype == "r1")
    {
        sess_gc("7200");
    }
    $rs = getdb("select count(sid) from k_sessions where uid!=2");
    if (!$rs->eof)
    {
        $onlinesum = $rs->f[0];
    }
    $rs->close();
    if ($member_max_limit < $onlinesum)
    {
        $conf->set("member_max_limit", $onlinesum);
    }
    $rStrArr[] = "\"onlinesum\":\"" . $onlinesum . "\"";
}
if (intval(getvar("useamount")))
{
    $cid = $curruser['id'];
    $sqlOpen = "SELECT open FROM lotto_{$tbl} WHERE id = {$lotto_id} LIMIT 0,1";
    $openRs = getdb($sqlOpen);
    if (!$openRs->eof)
    {
        $paperOpen = $openRs->f[0];
        switch ($show3D3S)
        {
            case 0 :
                $amountField = "amount_3d";
                $tblTemp = "3d";
                $sql01 = "select sum(a.amount) as amount from bet2_{$tblTemp} a LEFT JOIN lotto_{$tblTemp} b ON (a.lotto_id = b.id) where a.user_id = {$cid} and b.open = {$paperOpen} and a.rame in (0,9)";
                $sql01 .= " UNION ALL ";
                $tblTemp = "3t";
                $sql01 = "select sum(a.amount) as amount from bet2_{$tblTemp} a LEFT JOIN lotto_{$tblTemp} b ON (a.lotto_id = b.id) where a.user_id = {$cid} and b.open = {$paperOpen} and a.rame in (0,9)";
                break;
            case 1 :
                $amountField = "amount_3s1";
                $tblTemp = "3s1";
                $sql01 = "SELECT sum(a.amount) as amount FROM bet2_{$tblTemp} a LEFT JOIN lotto_{$tblTemp} b ON (a.lotto_id=b.id) WHERE a.user_id = {$cid} AND b.open='{$paperOpen}' AND a.rame IN (0,9)";
                $sql01 .= " UNION ALL ";
                $tblTemp = "3s2";
                $sql01 .= "SELECT sum(a.amount) as amount FROM bet2_{$tblTemp} a LEFT JOIN lotto_{$tblTemp} b ON (a.lotto_id=b.id) WHERE a.user_id = {$cid} AND b.open='{$paperOpen}' AND a.rame IN (0,9)";
                $sql01 .= " UNION ALL ";
                $tblTemp = "3s3";
                $sql01 .= "SELECT sum(a.amount) as amount FROM bet2_{$tblTemp} a LEFT JOIN lotto_{$tblTemp} b ON (a.lotto_id=b.id) WHERE a.user_id = {$cid} AND b.open='{$paperOpen}' AND a.rame IN (0,9)";
                break;
        }
        $rs = getdb($sql01);
        $usedamount = 0;
        while (!$rs->eof)
        {
            $usedamount += $rs->f[0];
            $rs->next();
        }
        $rs->close();
        $users = GetUserList($curruser['id']);
        if ($users != "")
        {
            switch ($show3D3S)
            {
                case 0 :
                    $tblTemp = "3d";
                    $sql02 = "select sum(a.amount) as amount from bet_{$tblTemp} a LEFT JOIN lotto_{$tblTemp} b ON (a.lotto_id = b.id) where b.open = '{$paperOpen}' AND a.user_id in ({$users}) and a.rame in (0,9)";
                    $sql02 .= " UNION ALL ";
                    $tblTemp = "3t";
                    $sql02 .= "select sum(a.amount) as amount from bet_{$tblTemp} a LEFT JOIN lotto_{$tblTemp} b ON (a.lotto_id = b.id) where b.open = '{$paperOpen}' AND a.user_id in ({$users}) and a.rame in (0,9)";
                    break;
                case 1 :
                    $tblTemp = "3s1";
                    $sql02 = "SELECT sum(a.amount) FROM bet_{$tblTemp} a LEFT JOIN lotto_{$tblTemp} b ON (a.lotto_id = b.id) WHERE a.user_id IN ({$users}) AND b.open='{$paperOpen}' AND a.rame IN (0,9)";
                    $sql02 .= " UNION ALL ";
                    $tblTemp = "3s2";
                    $sql02 .= "SELECT sum(a.amount) FROM bet_{$tblTemp} a LEFT JOIN lotto_{$tblTemp} b ON (a.lotto_id = b.id) WHERE a.user_id IN ({$users}) AND b.open='{$paperOpen}' AND a.rame IN (0,9)";
                    $sql02 .= " UNION ALL ";
                    $tblTemp = "3s3";
                    $sql02 .= "SELECT sum(a.amount) FROM bet_{$tblTemp} a LEFT JOIN lotto_{$tblTemp} b ON (a.lotto_id = b.id) WHERE a.user_id IN ({$users}) AND b.open='{$paperOpen}' AND a.rame IN (0,9)";
                    break;
            }
            $rs = getdb($sql02);
            while (!$rs->eof)
            {
                $usedamount += $rs->f[0];
                $rs->next();
            }
            $rs->close();
        }
        $usedamount = $curruser[$amountField] - $usedamount;
    } else
    {
        $usedamount = "--";
    }
    $openRs->close();
    $rStrArr[] = "\"useamount\":\"" . $usedamount . "\"";
}
$tempStr2 = "";
$getDiffTotalBettypesArr = array("rc", "r1all");
$RateConfig_5h->playtypeArr02['r1all'] = "全部";
if ($gametype == 20)
{
    $RateConfig_5h->playGroupArr02['r1all'] = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14");
} else
{
    $RateConfig_5h->playGroupArr02['r1all'] = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18");
}
foreach ($RateConfig_5h->playtypeArr02 as $key => $val)
{
    $bettypeTemp = implode(",", $RateConfig_5h->playGroupArr02[$key]);
    if (in_array($key, $getDiffTotalBettypesArr))
    {
        $theacl = $curruser['acl'];
        $bet_percent = "";
        $bet2_percent = "";
        $bet28 = "bet2";
        if ($split == 1)
        {
            switch ($theacl)
            {
                case 2 :
                    $bet_percent = " * percent2 / 100";
                    $bet2_percent = " * 0";
                    break;
                case 3 :
                    $bet_percent = " * percent3 / 100";
                    $bet2_percent = " * percent3 / 100";
                    break;
                case 4 :
                    $bet_percent = " * percent4 / 100";
                    $bet2_percent = " * percent4 / 100";
                    break;
                case 5 :
                    $bet_percent = " * percent5 / 100";
                    $bet2_percent = " * percent5 / 100";
                    break;
                default :
                    $bet_percent = " * percent255 / 100";
                    $bet2_percent = " * percent255 / 100";
                    $bet28 = "bet8";
            }
        }
        $speArr = $RateConfig_5h->playGroupArr02[$key];
        $betStr = 1 < count($speArr) ? " AND bettype IN (" . implode(",", $speArr) . ")" : " AND bettype = {$speArr[0]} ";
        $sql = "select sum(amount {$bet_percent}) as amount, max(createtime) as createtime from bet_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
        $sql2 = "select sum(amount {$bet2_percent}) as amount, max(createtime) as createtime from bet2_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
        $sql3 = "select sum(amount * -1) as amount, max(createtime) as createtime from bet2_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
        $sql8 = "select sum(amount * -1) as amount, max(createtime) as createtime from bet8_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
        if ($theacl != 255)
        {
            $userlist = GetUserList($curruser['id']);
            if ($userlist == "")
            {
                $sql .= " and 0=1 ";
            }
            $sql .= " and user_id in ({$userlist})";
            if (2 < $theacl)
            {
                $sql2 .= " and uperid{$theacl}=" . $curruser['id'] . " and user_id != " . $curruser['id'];
            }
            $sql3 .= " and user_id=" . $curruser['id'];
        }
        if (0 < $disk)
        {
            $sql .= " and disk=" . $disk;
        }
        if ($theacl == 255)
        {
            $sqlOK = "select sum(amount) as amount, max(createtime) as createtime from (";
            $sqlOK .= " {$sql} UNION ALL {$sql2} UNION ALL {$sql8} ) as tblA ";
        } else
        {
            $sqlOK = "select sum(amount) as amount, max(createtime) as createtime from (";
            $sqlOK .= " {$sql}";
            if (2 < $theacl)
            {
                $sqlOK .= " UNION ALL {$sql2}";
            }
            $sqlOK .= " UNION ALL {$sql3} ) as tblA ";
        }
        $sqlOKRS = getdb($sqlOK);
        $tnTemp = 0;
        $amuTemp = 0;
        while (!$sqlOKRS->eof)
        {
            if ($tnTemp < $sqlOKRS->f[1])
            {
                $tnTemp = $sqlOKRS->f[1];
            }
            $amuTemp += $sqlOKRS->f[0];
            $sqlOKRS->next();
        }
        $tempDataTotal = array();
        $tempDataTotal['amount'] = $amuTemp;
        $tempDataTotal['updatetime'] = $tnTemp;
    } else
    {
        $tempDataTotal = $BetTotal_5h->getDataListTotalForBettypeS($lotto_id, $bettypeTemp, $showid, $split, $diskStr, $xyid);
    }
    if ($tempDataTotal)
    {
        $tempStr2 .= ",{\"idx\":\"" . $key . "\", \"amu\":\"" . intval($tempDataTotal['amount']) . "\", \"tn\":\"" . $tempDataTotal['updatetime'] . "\"}";
    } else
    {
        $tempStr2 .= ",{\"idx\":\"" . $key . "\", \"amu\":\"0\", \"tn\":\"0\"}";
    }
}
$rStrArr[] = implode(",", $rtotalArr);
$rStrArr[] = "\"pgTotalAmountStr\":[" . substr($tempStr2, 1) . "]";
if ($playtype == "rc")
{
    $theacl = $curruser['acl'];
    $bet_percent = "";
    $bet2_percent = "";
    $bet28 = "bet2";
    if ($split == 1)
    {
        switch ($theacl)
        {
            case 2 :
                $bet_percent = " * percent2 / 100";
                $bet2_percent = " * 0";
                break;
            case 3 :
                $bet_percent = " * percent3 / 100";
                $bet2_percent = " * percent3 / 100";
                break;
            case 4 :
                $bet_percent = " * percent4 / 100";
                $bet2_percent = " * percent4 / 100";
                break;
            case 5 :
                $bet_percent = " * percent5 / 100";
                $bet2_percent = " * percent5 / 100";
                break;
            default :
                $bet_percent = " * percent255 / 100";
                $bet2_percent = " * percent255 / 100";
                $bet28 = "bet8";
                break;
        }
    }
    $betStr = 1 < count($playArr) ? " AND bettype IN (" . implode(",", $playArr) . ")" : " AND bettype = {$playArr[0]} ";
    $sql = "select sum(amount {$bet_percent}) as amount, count(amount) as totalnum, numbers, max(createtime) as createtime from bet_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
    $sql2 = "select sum(amount {$bet2_percent}) as amount, count(amount) as totalnum, numbers, max(createtime) as createtime from bet2_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
    $sql3 = "select sum(amount * -1) as amount, count(amount) as totalnum, numbers, max(createtime) as createtime from bet2_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
    $sql8 = "select sum(amount * -1) as amount, count(amount) as totalnum, numbers, max(createtime) as createtime from bet8_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
    if ($theacl != 255)
    {
        $userlist = GetUserList($curruser['id']);
        if ($userlist == "")
        {
            $sql .= " and 0=1 ";
        }
        $sql .= " and user_id in ({$userlist})";
        if (2 < $theacl)
        {
            $sql2 .= " and uperid{$theacl}=" . $curruser['id'] . " and user_id != " . $curruser['id'];
        }
        $sql3 .= " and user_id=" . $curruser['id'];
    }
    if (0 < $disk)
    {
        $sql .= " and disk=" . $disk;
    }
    $sql .= " GROUP BY numbers ";
    $sql2 .= " GROUP BY numbers ";
    $sql3 .= " GROUP BY numbers ";
    $sql8 .= " GROUP BY numbers ";
    if ($theacl == 255)
    {
        $sqlOK = "select sum(amount) as amount, sum(totalnum), numbers, max(createtime) as createtime from (";
        $sqlOK .= " {$sql} UNION ALL {$sql2} UNION ALL {$sql8} ) as tblA GROUP BY tblA.numbers ORDER BY amount DESC LIMIT 100";
    } else
    {
        $sqlOK = "select sum(amount) as amount, sum(totalnum), numbers, max(createtime) as createtime from (";
        $sqlOK .= " {$sql} ";
        if (2 < $theacl)
        {
            $sqlOK .= " UNION ALL {$sql2}";
        }
        $sqlOK .= " UNION ALL {$sql3} ) as tblA GROUP BY tblA.numbers ORDER BY amount DESC LIMIT 100";
    }
    $sqlOKRS = getdb($sqlOK);
    $sqlOKArr = array();
    while (!$sqlOKRS->eof)
    {
        if ($time < $sqlOKRS->f[3])
        {
            $bgclass = "namount";
        } else
        {
            $bgclass = "";
        }
        $sqlOKArr[] = "{\"amu\":\"" . intval($sqlOKRS->f[0]) . "\", \"tn\":\"" . round($sqlOKRS->f[1], 2) . "\", \"num\":\"" . $sqlOKRS->f[2] . "\", \"bgclass\":\"" . $bgclass . "\"}";
        $sqlOKRS->next();
    }
    $rStrArr[] = "\"rcNumGroup\" : [" . implode(",", $sqlOKArr) . "]";
}
if ($playtype == "rc")
{
    $theacl = $curruser['acl'];
    $bet_percent = "";
    $bet2_percent = "";
    $bet28 = "bet2";
    if ($split == 1)
    {
        switch ($theacl)
        {
            case 2 :
                $bet_percent = " * percent2 / 100";
                $bet2_percent = " * 0";
                break;
            case 3 :
                $bet_percent = " * percent3 / 100";
                $bet2_percent = " * percent3 / 100";
                break;
            case 4 :
                $bet_percent = " * percent4 / 100";
                $bet2_percent = " * percent4 / 100";
                break;
            case 5 :
                $bet_percent = " * percent5 / 100";
                $bet2_percent = " * percent5 / 100";
                break;
            default :
                $bet_percent = " * percent255 / 100";
                $bet2_percent = " * percent255 / 100";
                $bet28 = "bet8";
                break;
        }
    }
    $tempStr2 = "";
    foreach ($RateConfig_5h->playGroupArr02[$playtype] as $val2)
    {
        $betStr = " AND bettype = {$val2} ";
        $sql = "select sum(amount {$bet_percent}) as amount, max(createtime) as createtime from bet_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
        $sql2 = "select sum(amount {$bet2_percent}) as amount, max(createtime) as createtime from bet2_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
        $sql3 = "select sum(amount * -1) as amount, max(createtime) as createtime from bet2_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
        $sql8 = "select sum(amount * -1) as amount, max(createtime) as createtime from bet8_{$tbl} where lotto_id={$lotto_id} and rame in (0,9) {$betStr}";
        if ($theacl != 255)
        {
            $userlist = GetUserList($curruser['id']);
            if ($userlist == "")
            {
                $sql .= " and 0=1 ";
            }
            $sql .= " and user_id in ({$userlist})";
            if (2 < $theacl)
            {
                $sql2 .= " and uperid{$theacl}=" . $curruser['id'] . " and user_id != " . $curruser['id'];
            }
            $sql3 .= " and user_id=" . $curruser['id'];
        }
        if (0 < $disk)
        {
            $sql .= " and disk=" . $disk;
        }
        if ($theacl == 255)
        {
            $sqlOK = "select sum(amount) as amount, max(createtime) as createtime from (";
            $sqlOK .= " {$sql} UNION ALL {$sql2} UNION ALL {$sql8} ) as tblA ";
        } else
        {
            $sqlOK = "select sum(amount) as amount, max(createtime) as createtime from (";
            $sqlOK .= " {$sql}";
            if (2 < $theacl)
            {
                $sqlOK .= " UNION ALL {$sql2}";
            }
            $sqlOK .= " UNION ALL {$sql3} ) as tblA ";
        }
        $sqlOKRS = getdb($sqlOK);
        $tnTemp = 0;
        $amuTemp = 0;
        while (!$sqlOKRS->eof)
        {
            if ($tnTemp < $sqlOKRS->f[1])
            {
                $tnTemp = $sqlOKRS->f[1];
            }
            $amuTemp += $sqlOKRS->f[0];
            $sqlOKRS->next();
        }
        $tempDataTotal = array();
        $tempDataTotal['amount'] = $amuTemp;
        $tempDataTotal['updatetime'] = $tnTemp;
        $tempStr2 .= ",{\"idx\":\"" . $val2 . "\", \"amu\":\"" . intval($tempDataTotal['amount']) . "\", \"tn\":\"" . $tempDataTotal['updatetime'] . "\"}";
    }
    $rStrArr[] = "\"pgBtnTotalAmu\":[" . substr($tempStr2, 1) . "]";
} else if (in_array($playtype, $RateConfig_5h->showAllBetArr02))
{
    $tempStr2 = "";
    foreach ($RateConfig_5h->playGroupArr02[$playtype] as $val)
    {
        $tempDataTotal = $BetTotal_5h->getDataListTotalForBettypeS($lotto_id, $val, $showid, $split, $diskStr, $xyid);
        if ($tempDataTotal)
        {
            $tempStr2 .= ",{\"idx\":\"" . $val . "\", \"amu\":\"" . intval($tempDataTotal['amount']) . "\", \"tn\":\"" . $tempDataTotal['updatetime'] . "\"}";
        } else
        {
            $tempStr2 .= ",{\"idx\":\"" . $val . "\", \"amu\":\"0\", \"tn\":\"0\"}";
        }
    }
    $rStrArr[] = "\"pgBtnTotalAmu\":[" . substr($tempStr2, 1) . "]";
} else if (in_array($playtype, $RateConfig_5h->showAllSubArr02))
{
    $tempStr2 = "";
    $maxI = $RateConfig_5h->maxSubId + 1;
    $i = 1;
    while ($i < $maxI)
    {
        $tempDataTotal = $BetTotal_5h->getDataListTotalForBettypeS($lotto_id, $playArr[0], $showid, $split, $diskStr, $xyid, $i);
        if ($tempDataTotal)
        {
            $tempStr2 .= ",{\"idx\":\"" . $i . "\", \"amu\":\"" . intval($tempDataTotal['amount']) . "\", \"tn\":\"" . $tempDataTotal['updatetime'] . "\"}";
        } else
        {
            $tempStr2 .= ",{\"idx\":\"" . $i . "\", \"amu\":\"0\", \"tn\":\"0\"}";
        }
        ++$i;
    }
    $rStrArr[] = "\"pgBtnTotalAmu\":[" . substr($tempStr2, 1) . "]";
}
$rStrArr[] = "\"_5hFlag\" : \"" . ( 20 < $gametype ? "false" : "true" ) . "\"";
header("Cache-Control: no-cache, must-revalidate");
header("Content-Type: text/plain");
echo "{" . implode(",", $rStrArr) . "}";
exit();